package cn.csust.net2.manager.client.ux;

import cn.csust.net2.manager.shared.po.PO;

import com.extjs.gxt.ui.client.data.BeanModel;
import com.extjs.gxt.ui.client.event.ButtonEvent;
import com.extjs.gxt.ui.client.event.GridEvent;
import com.extjs.gxt.ui.client.event.SelectionListener;
import com.extjs.gxt.ui.client.widget.grid.Grid;
import com.extjs.gxt.ui.client.widget.grid.RowEditor;

/**
 * 
 * @author Administrator
 * 
 * @param <T>
 */
public class BeanRowEditor<T extends PO> extends RowEditor<BeanModel> {

	private boolean isAdd = true;

	public BeanRowEditor() {
		super();
	}

	/**
	 * 重写鼠标单击事件，只有在鼠标双击的时候才编辑
	 */
	@Override
	protected void onRowClick(GridEvent<BeanModel> e) {
		// TODO Auto-generated method stub
	}
	
	@Override
	protected void afterRender() {
		// TODO Auto-generated method stub
		super.afterRender();
		this.saveBtn.setText("保存");
		this.cancelBtn.setText("取消");
		this.cancelBtn.removeAllListeners();
		this.cancelBtn.addSelectionListener(new SelectionListener<ButtonEvent>() {
			
			@Override
			public void componentSelected(ButtonEvent ce) {
				// TODO Auto-generated method stub
				if(isAdd) {
					stopEditing(false);
					getGrid().getStore().remove(0);
					getGrid().getView().refresh(false);
				} else {
					stopEditing(false);
				}
			}
		});
	}
	
	public Grid<BeanModel> getGrid() {
		return this.grid;
	}
	
	public boolean isAdd() {
		return isAdd;
	}

	public void setAdd(boolean isAdd) {
		this.isAdd = isAdd;
	}

}
